package com.codedancer.campus.client.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.service.ICircleLabelService;
import com.codedancer.campus.client.service.vo.circle.CircleLabelVo;
import com.codedancer.campus.common.exception.BusinessException;
import com.codedancer.campus.mapper.CircleLabelMapper;
import com.codedancer.campus.mapper.CircleMapper;
import com.codedancer.campus.po.CircleLabel;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class CircleLabelServiceImpl implements ICircleLabelService {

    @Autowired
    private CircleLabelMapper circleLabelMapper;
    @Autowired
    private CircleMapper circleMapper;

    /**
     * 获取圈子标签
     *
     * @param circleUuid
     * @return
     */
    @Override
    public List<CircleLabelVo> list(String circleUuid) {
        if (!circleMapper.existsByUuId(circleUuid)) {
            throw new BusinessException("圈子不存在");
        }
        List<CircleLabel> circleLabels = circleLabelMapper.selectListByColumn("circle_uuid",circleUuid);
        return circleLabels.stream().map(circleLabel -> {
            return BeanUtil.copyProperties(circleLabel, CircleLabelVo.class);
        }).collect(Collectors.toList());
    }
}
